/******************************************************************
 * Copyright (c) 2011 - 2016, Simon Guerard, All rights reserved.
 * 
 * Projet de jeu de course au larg a la voile.
 * 
 * This File is part of Sail-race
 * 
 * Sail-race is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 * 
 * Sail-race is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with Sail-race; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.simcafamily.sailrace;

import net.simcafamily.sailrace.core.IControleur;
import net.simcafamily.sailrace.spring.ContextFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Main {

    private static final Log LOGGER = LogFactory.getLog(Main.class);

    // fin anormale
    private static void abort(final String message, final Exception ex,
	    final int exitCode) throws Exception {
	// on affiche l'erreur
	Main.LOGGER.error(message, ex);
	// on s'arrete
	System.exit(exitCode);
    }

    public static void main(final String[] args) throws Exception {
	// message de patience
	Main.LOGGER.info("Application en cours d'initialisation. Patientez...");
	try {
	    // SwingUtilities.invokeLater(new Runnable() {
	    // @Override
	    // public void run() {
	    IControleur controleur = (IControleur) ContextFactory.getContext()
		    .getBean("controleur");
	    controleur.run();
	    // }
	    // });

	    Main.LOGGER.info("Lancement Sail Race!");
	} catch (final Exception ex) {
	    // on s'arrete
	    Main.abort("Erreur lors de l'initialisation du controleur", ex, 1);
	}
	// execution application
	Main.LOGGER.info("Application lancee...");
    }

}
